css: Handle invalid :not() selectors
authorBenjamin Otte <otte@redhat.com>
Mon, 2 Dec 2019 16:31:15 +0000 (17:31 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 3 Dec 2019 17:12:25 +0000 (18:12 +0100)
We weren't correctly ending the ( ) block when encountering an error.

Testcases added.

Fixes #2281

gtk/gtkcssselector.c
testsuite/css/parser/meson.build
testsuite/css/parser/not-unclosed.css [new file with mode: 0644]
testsuite/css/parser/not-unclosed.errors [new file with mode: 0644]
testsuite/css/parser/not-unclosed.ref.css [new file with mode: 0644]

index 89ec18194fafcbd50abf2c6a5341db1205fd8f90..b6468bd28266854540477cb092a12b072a0d9d83 100644 (file)
@@ -1396,6 +1396,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser   *parser,
               else
                 {
                   gtk_css_parser_error_syntax (parser, "Invalid contents of :not() selector");
+                  gtk_css_parser_end_block (parser);
                   if (selector)
                     _gtk_css_selector_free (selector);
                   selector = NULL;
@@ -1406,6 +1407,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser   *parser,
               if (!gtk_css_token_is (token, GTK_CSS_TOKEN_EOF))
                 {
                   gtk_css_parser_error_syntax (parser, "Invalid contents of :not() selector");
+                  gtk_css_parser_end_block (parser);
                   if (selector)
                     _gtk_css_selector_free (selector);
                   selector = NULL;
index 1e171aaa3630c36edc5bb9daf8c4093776bb14bd..607faab0bbff7a11ef5d8127d64e7a3115ee4343 100644 (file)
@@ -369,6 +369,9 @@ test_data = [
   'no-semicolon.ref.css',
   'not.css',
   'not.ref.css',
+  'not-unclosed.css',
+  'not-unclosed.errors',
+  'not-unclosed.ref.css',
   'nth-child.css',
   'nth-child.ref.css',
   'opacity.css',
diff --git a/testsuite/css/parser/not-unclosed.css b/testsuite/css/parser/not-unclosed.css
new file mode 100644 (file)
index 0000000..06a8011
--- /dev/null
@@ -0,0 +1,3 @@
+:not(valid invalid) {}
+
+:not(
diff --git a/testsuite/css/parser/not-unclosed.errors b/testsuite/css/parser/not-unclosed.errors
new file mode 100644 (file)
index 0000000..f83d9d7
--- /dev/null
@@ -0,0 +1,3 @@
+not-unclosed.css:1:12-19: error: GTK_CSS_PARSER_ERROR_SYNTAX
+not-unclosed.css:4:1: error: GTK_CSS_PARSER_ERROR_SYNTAX
+not-unclosed.css:3:2-4:1: error: GTK_CSS_PARSER_WARNING_SYNTAX
diff --git a/testsuite/css/parser/not-unclosed.ref.css b/testsuite/css/parser/not-unclosed.ref.css
new file mode 100644 (file)
index 0000000..e69de29